package Game;


public class Deck 
{
	private Card[] deck; // array of 52 cards
	private int cardsUsed; // how many cards have been dealt from deck.
	
	/**
	 * creates an unshuffled deck of cards
	 */
	public Deck()
	{
		deck = new Card[52];
		int cardCt = 0;//how many cards have been created so far
		for(int suit = 0; suit <=3; suit++)
		{
			for(int value = 1; value<= 13; value++)
			{
				deck[cardCt] = new Card(value,suit);
				cardCt++;
			}
		}
		cardsUsed = 0;
	}
	/**
	 * put all the used cards back into the deck,
	 * and shuffle it into a random order
	 */
	public void shuffle()
	{
		for(int i = 51; i>0;i--)
		{
			int rand = (int)(Math.random()*(i+1));
			Card temp = deck[i];
			deck[i] = deck[rand];
			deck[rand] = temp;
		}
		cardsUsed = 0;
	}
	/**
	 * as cards are dealt from the deck, the number of
	 * cards left decreases. this functions returns the
	 * number of cards that are still left in the deck.
	 * @return number of cards left
	 */
	public int cardsLeft()
	{
		return 52 - cardsUsed;
	}
	/**
	 * deals one cards from the deck and returns it
	 * @return a cards from deck
	 */
	
	//if cardsUsed ==52, can also be stop dealing
	public Card dealCard()
	{
		if(cardsUsed == 52)
		{
			//shuffle();
			return null;//or try sth else
		}
		cardsUsed++;
		return deck[cardsUsed - 1];
	}

}
